<template>
  <div class="temp90">
    <VBg bgc="#fff" />
    <!-- <VHead ref="vHead" /> -->
    <div class="main">
      <!-- <RightLeave :leavingClass="leavingClass" /> -->
      <MainCont
        :stay-class="stayClass"
        :gone-class="goneClass"
        :leaving-class="leavingClass"
      />
    </div>
  </div>
</template>

<script>
import VBg from '@/modules/base/VBg.vue'
// import VHead from './Head.vue'
// import RightLeave from './RightLeave.vue'
import MainCont from './MainCont.vue'
import ajaxApi from '@/modules/ajax-api'
export default {
  components: {
    VBg,
    // VHead,
    // RightLeave,
    MainCont
  },
  data () {
    return {
      stayClass: [],
      leavingClass: [],
      goneClass: []
    }
  },
  created () {
    this.loadData()
  },
  // beforeRouteUpdate (to, from, next) {
  //   if (to.query.reload) {
  //     this.loadData()
  //     this.$refs.vHead.loadData()
  //   }
  //   next()
  // },
  methods: {
    loadData () {
      ajaxApi.classesByOverType().then(data => {
        let classes = data.classes
        if (classes.length === 0) return

        function add (item, arr, objDirt, key) {
          let obj = objDirt[key]
          let classes
          if (obj === undefined) {
            classes = []
            obj = objDirt[key] = {
              id: key,
              name: item.grade_name,
              gradeType: item.grade_id1,
              classes
            }
            arr.push(obj)
          } else {
            classes = obj.classes
          }
          classes.push({
            id: item.class_id,
            name: item.class_name
          })
        }

        let stayClass = []
        let stayClassKey = {}
        let leavingClass = []
        let leavingClassKey = {}
        let goneClass = []
        let goneClassKey = {}
        classes.forEach(d => {
          switch (d.over_type) {
            case '0': // 留校
              add(d, stayClass, stayClassKey, d.grade_id)
              break
            case '2': // 正在离校
              add(d, leavingClass, leavingClassKey, d.grade_id)
              break
            case '3': // 已离校
              add(d, goneClass, goneClassKey, d.grade_id)
              break
          }
        })
        this.stayClass = stayClass
        this.leavingClass = leavingClass
        this.goneClass = goneClass
      })
    }
    // gradClassSort (grad) {
    //   classSort (cla) {
    //     cla.sort(function (v1, v2) {
    //       return v1.class_name.localeCompare(v2.class_name, 'zh')
    //     })
    //   }
    //   grad.sort(function (v1, v2) {
    //     return v1.gradeType > v2.gradeType
    //   })
    // },
  }
}
</script>

<style scoped>
.temp90 {
  font-size: 200px;
}
.main {
  padding: 0.1em;
  position: fixed;
  left: 0;
  right: 0;
  /* top: 0.8em; */
  top: 0;
  bottom: 0;
}
</style>
